<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

class Record extends Model
{
    protected $table='park_record';
    protected $guarded=[];
    protected $primaryKey='RID';
    public $timestamps=false;
    
    protected static function boot()
    {
        parent::boot();
        
        static::addGlobalScope('status', function(Builder $builder) {
            $builder->where('ParkStatus', 1);
        });
    }
    
    //获取统一的车辆状态
    public function getStatusAttribute()
    {
        if($this->attributes['ParkStatus'] == 0){
            return 2;
        }
        return 1;
    }
    
    public function car()
    {
        return $this->hasOne(Car::class,'CarID','CarID');
    }
    
    public function myCar()
    {
        return $this->hasOne(MyCar::class,'ID','myCarID');
    }
    
    public function carOwner()
    {
        return $this->hasOne(Member::class,'uid','ParkUid');
    }
    public function parkingOwner()
    {
        return $this->hasOne(Member::class,'uid','ParkWhoUid');
    }
    
}
